/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function DrawChart(){    
    var chart;
    var options = {
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'line'
        },
        title: {            
            x: -20 //center
        },        
        xAxis: {
            title: {                
            },
            categories : []
        },
        yAxis: {
            title: {
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y + ' (VND)';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        credits : {
            enabled:false
        },
        series: []
    };    
    $.getJSON("../BieuDo_Controller?action=getmonth", function (data)
    {
        options.xAxis.categories = data[0].value;
        options.xAxis.title.text = data[0].label;
        options.yAxis.title.text = data[1].label;
        options.title.text = data[1].value;
        $.getJSON("../BieuDo_Controller?action=chartline", function (data)
        {
            //var series = []; // <---------------------- must be object not array
            for (var i = 0; i < data.length; i++)
            {
                var series = {}; // <-------------------- moved and changed to object
                series.name = data[i].label;
                series.data = data[i].value;
                options.series.push(series); //
            }
            chart = new Highcharts.Chart(options);
        });
    });    
}
function FoodChart(){
    var chart;
    var options = {
        chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: Highcharts.theme.textColor || '#000000',
                    connectorColor: Highcharts.theme.textColor || '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
                    }
                }
            }
        },
        credits : {
            enabled:false
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                     
        ]
        }]
    }
    $.getJSON("BieuDo_Controller?action=gettilechartfood", function (data)
    {
        options.title.text = data[0].label;
        $.getJSON("BieuDo_Controller?action=foodchart", function (data)
        {
            for (var i = 0; i < data.length; i++)
            {
                var tam = {};
                tam.name = data[i].name;
                tam.y = data[i].y;
                tam.sliced = data[i].sliced;
                tam.selected = data[i].selected;
                options.series[0].data.push(tam);
            }
            chart = new Highcharts.Chart(options);
        });
    });
}
function AreaChart(){
    var chart;
    var options = {
        chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {

        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: Highcharts.theme.textColor || '#000000',
                    connectorColor: Highcharts.theme.textColor || '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
                    }
                }
            }
        },
        credits : {
            enabled:false
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [

        ]
        }]
    }
    $.getJSON("BieuDo_Controller?action=gettilechartarea", function (data)
    {
        options.title.text = data[0].label;
        $.getJSON("BieuDo_Controller?action=areachart", function (data)
        {
            for (var i = 0; i < data.length; i++)
            {
                var tam = {};
                tam.name = data[i].name;
                tam.y = data[i].y;
                tam.sliced = data[i].sliced;
                tam.selected = data[i].selected;
                options.series[0].data.push(tam);
            }
            chart = new Highcharts.Chart(options);
        });
    });
}
function TurnoverChart(year){
    
    var chart;
    var options = {
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'line'
        },
        title: {
            x: -20 //center
        },
        xAxis: {
            title: {
            },
            categories : []
        },
        yAxis: {
            title: {
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y + ' (VND)';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        credits : {
            enabled:false
        },
        series: []
    };
    $.getJSON("BieuDo_Controller?action=getmonth", function (data)
    {
        options.xAxis.categories = data[0].value;
        options.xAxis.title.text = data[0].label;
        options.yAxis.title.text = data[1].label;
        options.title.text = data[1].value;
        $.getJSON("ThongKe_Controller?action=chartline&year="+year+"", function (data)
        {
            //var series = []; // <---------------------- must be object not array
            for (var i = 0; i < data.length; i++)
            {
                var series = {}; // <-------------------- moved and changed to object
                series.name = data[i].label;
                series.data = data[i].value;
                options.series.push(series); //
            }
            chart = new Highcharts.Chart(options);
        });
    });
}